package com.bridgeQQ.client.service.channels
{
	import mx.core.mx_internal;
	import mx.messaging.MessageResponder;
	import mx.messaging.channels.AMFChannel;
	import mx.messaging.messages.CommandMessage;
	import mx.messaging.messages.IMessage;
	import mx.messaging.messages.ISmallMessage;
	import mx.messaging.messages.MessagePerformanceInfo;
	import mx.messaging.messages.MessagePerformanceUtils;
	
	use namespace mx_internal;
	public class PeerNotificatonChannel extends AMFChannel
	{
		private var _peerID:String;
		
		public function PeerNotificatonChannel(id:String=null, uri:String=null)
		{
			super(id, uri);
		}
		
		override protected function internalSend(msgResp:MessageResponder):void
	    {
	    	//add peerID into command msg header
	    	var cm:CommandMessage = msgResp.message as CommandMessage;
	    	if(cm != null && cm.operation == CommandMessage.SUBSCRIBE_OPERATION)
	    	{
	    		cm.headers.peerID = this.peerID;
	    	}
	        // Set the global FlexClient Id.
	        setFlexClientIdOnMessage(msgResp.message);
	
	        // If MPI is enabled initialize MPI object and stamp it with client send time
	        if (mpiEnabled)
	        {
	            var mpii:MessagePerformanceInfo = new MessagePerformanceInfo();
	            if (recordMessageTimes)
	                mpii.sendTime = new Date().getTime();
	            msgResp.message.headers[MessagePerformanceUtils.MPI_HEADER_IN] = mpii;
	        }
	
	        var message:IMessage = msgResp.message;
	
	        // Finally, if "Small Messages" are enabled, send this form instead of
	        // the normal message where possible.
	        if (useSmallMessages && message is ISmallMessage)
	        {
	            var smallMessage:IMessage = ISmallMessage(message).getSmallMessage();
	            if (smallMessage != null)
	                message = smallMessage;
	        }
	
	        _nc.call(null, msgResp, message);
	    }
	    
	    public function set peerID(value:String):void
	    {
	    	_peerID = value;
	    }
	    
	    public function get peerID():String
	    {
	    	return _peerID;
	    }
	}
}